#!/bin/bash

#
# Copyright (c) 2019-2020
# Author: LIU Xiangyu
# File: postinst
# Description:
#

printf "\n>>> adjust networkd service.\n"
SERVICE_NETWORKD=/lib/systemd/system/systemd-networkd-wait-online.service
CONTROL_NETWORKD="TimeoutStartSec=3sec"
target=$(sed -n '/^TimeoutStartSec/=' $SERVICE_NETWORKD)
if [[ $target == "" ]]; then
  line=$(sed -n '/^\[Service/=' $SERVICE_NETWORKD)
  sed -i -e "${line}a${CONTROL_NETWORKD}" $SERVICE_NETWORKD
else
  line=$target
  sed -i -e "${line}a${CONTROL_NETWORKD}" -e "${line}d" $SERVICE_NETWORKD
fi


printf ">>> enable pc speaker.\n"
sed -i 's/^blacklist pcspkr/# &/' /etc/modprobe.d/blacklist.conf


printf ">>> update kernel.\n"
depmod -a
modprobe LXV4L2D_PL330B


printf ">>> check config.\n"
/usr/bin/mbox-ctl config check


printf ">>> enable services...\n"
SERVICE_CORE=mbox-core.service
systemctl daemon-reload
systemctl enable $SERVICE_CORE
systemctl start $SERVICE_CORE

printf ">>> REMEMBER to set platform"
mbox-ctl platform set 1

exit 0
